//
//  MSGameManager.h
//  MagicSword
//
//  Created by Netease on 15/11/20.
//  Copyright © 2015年 Jonear. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "MSTileMap.h"
#import "MSHeroInfo.h"
#import "MSFightScene.h"

@class MSHeroSprite;
@class MSEnemySprite;
typedef NS_ENUM(NSInteger, MSHeroSpriteStatus) {
    MSHeroSpriteStatus_Normal,          // 1.准备状态
    MSHeroSpriteStatus_Selected,        // 2.选中状态
    MSHeroSpriteStatus_Runed,           // 3.已移动
    MSHeroSpriteStatus_Finish,          // 4.已接受操作
};

@protocol MSGameManagerDelegate <NSObject>

- (void)gameOver:(BOOL)isWin;

@end

@interface MSGameManager : NSObject

+ (id)shareManager;

@property (strong, nonatomic) MSTileMap *curtitleMap;
@property (assign, nonatomic) NSInteger  session;
@property (assign, nonatomic) NSInteger  chapter;
@property (assign, nonatomic) float      gameScale;
@property (assign, nonatomic) CGSize     mapSize;
@property (assign, nonatomic) CGSize     tileSize;

@property (assign, nonatomic) NSInteger  roundCount;    //当前回合数

@property (weak, nonatomic) id<MSGameManagerDelegate> delegate;

// 设置地图
- (MSTileMap *)setMapWithSession:(NSInteger)session chapter:(NSInteger)chapter;
- (NSArray *)getHeroArray;
- (NSArray *)getEnemyArray;
// 获得敌人通过位置
- (MSEnemySprite *)getEnemyWithPoint:(CGPoint)point;
- (MSEnemySprite *)getEnemyWithCoord:(CGPoint)coord;
// 精灵可移动的位置数组
- (NSArray *)getHeroMoveArray:(CGPoint)curPoint canMoveValue:(NSInteger)moveValue;
// 获得敌方移动后可攻击的最近英雄
- (MSHeroSprite *)getEnemyAttackWithCoord:(CGPoint)curCoord canAttackValue:(MSAttackDistanceType)attackValue;
// 获得敌方移动到最近英雄的位置
- (CGPoint)moveEnemyNearByHero:(CGPoint)curCoord canMoveValue:(NSInteger)moveValue;
// 消灭敌人
- (void)removeEnemy:(MSEnemySprite *)enemy;
// 英雄可攻击的选择框
- (NSArray *)getHeroAttackArray:(CGPoint)curPoint canAttackDistance:(MSAttackDistanceType)attackDistance;
// 过关
- (void)passChapter:(NSInteger)session chapter:(NSInteger)chapter;
// 获得下一个要移动的英雄
- (MSHeroSprite *)getFirstNormalHero;
// 获得某个等级所需要的经验值
- (NSInteger)getLevelNeedExperience:(NSInteger)level;

// 加入英雄
- (void)addHeroWithSession:(NSInteger)session chapter:(NSInteger)chapter;
- (void)addHeroWithSession:(NSInteger)session chapter:(NSInteger)chapter inGameBegin:(BOOL)inGameBegin;

// 获取装备
- (void)getItemWithHero:(MSHeroInfo *)heroInfo point:(CGPoint)point;

// 开门
- (void)openDoorWithType:(int)type;

// 是否完成英雄回合
- (BOOL)checkFinishHeroRound;
- (void)reloadHeroRound;

// 武器是否破损
- (void)checkWeaponIsOutUse:(MSHeroInfo *)hero;
// 武器是否相克
- (BOOL)isWeaponWin:(MSWeaponType)attackWeapon dWeapon:(MSWeaponType)dWeapon;
// 敌方回合进行
- (NSArray *)runEnemyRound;

// 攻击
- (MSFightScene *)attackEnemy:(MSHeroSprite *)hero enemyPoint:(CGPoint)enemyPoint;
- (MSFightScene *)attackEnemy:(MSHeroSprite *)hero enemy:(MSEnemySprite *)enemy;
- (MSFightScene *)attackEnemy:(MSHeroSprite *)hero enemy:(MSEnemySprite *)enemy completion:(MSCompletionBlock)block;
- (MSFightScene *)attackEnemy:(MSHeroSprite *)hero enemy:(MSEnemySprite *)enemy isHeroAttack:(BOOL)isHeroAttack completion:(MSCompletionBlock)block;
- (CGFloat)attackHPEnemy:(MSHeroInfo *)hero enemy:(MSEnemyInfo *)enemy;
- (CGFloat)attackHPHero:(MSHeroInfo *)hero enemy:(MSEnemyInfo *)enemy;

// 是否连击 默认10% 武器克+10% +个人特性 +武器特性
- (BOOL)isCanDoubleHit:(MSHeroInfo *)hero enemy:(MSEnemyInfo *)enemy isHeroAttack:(BOOL)isHeroAttack;
// 是否回击 默认40% 武器克+20%
- (BOOL)isCanBackHit:(MSHeroInfo *)hero enemy:(MSEnemyInfo *)enemy isHeroAttack:(BOOL)isHeroAttack;

- (BOOL)isCanMoveWithCoord:(CGPoint)point;

- (void)moveto:(CGPoint)coord sprite:(SKSpriteNode *)sprite;
- (void)moveto:(CGPoint)coord sprite:(SKSpriteNode *)sprite completion:(MSCompletionBlock)block;
- (void)moveMapTo:(float)top;
- (void)moveMapTo:(float)top animated:(BOOL)animated;
- (void)moveMapWithSpriteTop:(float)top animated:(BOOL)animated;
- (void)moveMaptToNextNormalHero;

// 经验
- (BOOL)isLevelUp:(MSHeroSprite *)sprite;
- (NSInteger)getLevelUPNeedEx:(NSInteger)level;

// 坐标转换
- (CGPoint)PointFromCoord:(CGPoint)point;
- (CGPoint)CoordFromPoint:(CGPoint)point;
@end
